var app = getApp(),
  appkey = require("../../utils/ald-stat-conf.js"),
  bmap = require("../../libs/bmap-wx.js");

Page({
  data: {
    ps: !1,
    lunboimgs: ["/hyb_jianzhi/images/lunbo1.jpg", "/hyb_jianzhi/images/lunbo2.jpg", "/hyb_jianzhi/images/lunbo3.jpg", "/hyb_jianzhi/images/lunbo4.jpg"],
    padbot: 0,
    fx_popenid: "",
    city: "长沙市",
    keArr: [],
    pageWrapCount: [],
    keArrs: [],
    pageWrapCounts: [],
    none: [{
      img: "/hyb_jianzhi/images/none.png",
      con: "暂无兼职"
    }],
    page: 0,
    pagesize: 8,
    scrollTop: 0,
    is_hy: 0,
    scrollHeight: 0,
    getUseInfo: !0,
    u_id: "",
    close: !1,
    userinfo: "",
    H: 20,
    H2: 40,
    H3: 25,
    H4: 30,
    base: "",
    weatherData: ""
  },
  onLoad: function(a) {
    var r = this,
      t = a.a_id;
    if (app.util.request({
        url: "entry/wxapp/Key",
        success: function(a) {
          console.log(a.data.data);
          var t = a.data.data;
          appkey.app_key = t.app_key, appkey.appid = t.appid, appkey.appsecret = t.appsecret;
        }

      }), null == t) var e = "长沙市";
    else e = "长沙市";
    wx.getStorageSync("openid");
    if (r.getUsers(), "" != e ? (app.util.request({
        url: "entry/wxapp/Base",
        success: function(a) {
          r.setData({
            base: a.data.data,
            city: e
          });
          var n = a.data.data;
          console.log(n), wx.setNavigationBarTitle({
            title: a.data.data.name
          }), "1" == a.data.data.p_type ? (r.setData({
            ps: !0
          }), r.getPiandaohang()) : (r.setData({
            ps: !1
          }), r.getDaohang()), "0" == n.is_xn ? app.util.request({
            url: "entry/wxapp/Huizong",
            success: function(a) {
              console.log(a);
              for (var t = [{
                  title: "合作企业",
                  number: a.data.data.shop
                }, {
                  title: "职位数",
                  number: a.data.data.work
                }, {
                  title: "简历数",
                  number: a.data.data.jianli
                }, {
                  title: "访问量",
                  number: a.data.data.fanwen
                }], e = 0; e < t.length; e++) 5 == t[e].number.length ? 0 == t[e].number[1] ? t[e].number = t[e].number.substring(0, 1) + "万" : t[e].number = t[e].number.substring(0, 1) + "." + t[e].number.substring(1, 2) + "万" : 6 == t[e].number.length ? 0 == t[e].number[2] ? t[e].number = t[e].number.substring(0, 2) + "万" : t[e].number = t[e].number.substring(0, 2) + "." + t[e].number.substring(3, 4) + "万" : 7 == t[e].number.length && (0 == t[e].number[3] ? t[e].number = t[e].number.substring(0, 3) + "万" : t[e].number = t[e].number.substring(0, 3) + "." + t[e].number.substring(3, 4) + "万");
              r.setData({
                summary: t
              });
            }
          }) : app.util.request({
            url: "entry/wxapp/Huizong",
            success: function(a) {
              console.log(a);
              for (var t = [{
                  title: "入驻企业",
                  number: String(parseInt(a.data.data.shop) + parseInt(n.rz_qy))
                }, {
                  title: "职位",
                  number: String(parseInt(a.data.data.work) + parseInt(n.job))
                }, {
                  title: "简历",
                  number: String(parseInt(a.data.data.jianli) + parseInt(n.infos))
                }, {
                  title: "访问",
                  number: String(parseInt(a.data.data.fanwen) + parseInt(n.avtives))
                }], e = 0; e < t.length; e++) 5 == t[e].number.length ? 0 == t[e].number[1] ? t[e].number = t[e].number.substring(0, 1) + "万" : t[e].number = t[e].number.substring(0, 1) + "." + t[e].number.substring(1, 2) + "万" : 6 == t[e].number.length ? 0 == t[e].number[2] ? t[e].number = t[e].number.substring(0, 2) + "万" : t[e].number = t[e].number.substring(0, 2) + "." + t[e].number.substring(3, 4) + "万" : 7 == t[e].number.length && (0 == t[e].number[3] ? t[e].number = t[e].number.substring(0, 3) + "万" : t[e].number = t[e].number.substring(0, 3) + "." + t[e].number.substring(3, 4) + "万");
              r.setData({
                summary: t
              });
            }
          });
        }
      }), r.getJianzhi_show(), wx.getLocation({
        type: "wgs84",
        success: function(a) {
          var t = a.longitude,
            e = a.latitude,
            n = a.speed,
            i = a.accuracy;
          app.util.request({
            url: "entry/wxapp/Weizhi",
            cachetime: "30",
            data: {
              latitude: e,
              longitude: t,
              openid: wx.getStorageSync("openid"),
              speed: n,
              accuracy: i
            }
          });
        }
      })) : app.util.request({
        url: "entry/wxapp/Base",
        success: function(a) {
          console.log("succ");
          a.data.data;
          r.setData({
            base: a.data.data
          }), "1" == a.data.data.p_type ? (r.setData({
            ps: !0
          }), r.getPiandaohang()) : (r.setData({
            ps: !1
          }), r.getDaohang()), wx.setNavigationBarTitle({
            title: a.data.data.name
          });
          // var s = a.data.data.baidukey;
          var s = "yXpvFnM5Y3sRCYeKDhhQeeeLN5KQLrcH";
          // console.log("baidukey:" + a.data.data.baidukey);
          // console.log("key:" + s);
          wx.getLocation({
            type: "wgs84",
            success: function(a) {
              var t = a.longitude,
                e = a.latitude,
                n = a.speed,
                i = a.accuracy;
              app.util.request({
                url: "entry/wxapp/Weizhi",
                cachetime: "30",
                data: {
                  latitude: e,
                  longitude: t,
                  openid: wx.getStorageSync("openid"),
                  speed: n,
                  accuracy: i
                }
              }), wx.request({
                url: "https://api.map.baidu.com/geocoder/v2/?ak=" + s + "&location=" + e + "," + t + "&output=json",
                data: {},
                header: {
                  "Content-Type": "application/json"
                },
                success: function(a) {
                  console.log(a.data.result);
                  var t = a.data.result.addressComponent.city;
                  console.log(a), wx.setStorageSync("city", a.data.result.addressComponent.city),
                    r.setData({
                      city: t
                    }), r.getJianzhi_show();
                }
              });
            }
          });
        }
      }), r.setData({
        fx_popenid: a.fx_popenid
      }), "" != wx.getStorageSync("useInfo")) {
      var n = !1;
      r.setData({
        getUseInfo: n
      });
    } else {
      n = !0;
      r.setData({
        getUseInfo: n
      });
    }
    r.getJianzhi_type(), r.getPianlist(), r.getHuandengpian();
    setInterval(function() {
      var a = r.data.H;
      r.data.H2, r.data.H3, r.data.H4;
      20 == a ? r.setData({
        H: 30,
        H2: 25,
        H3: 35,
        H4: 20
      }) : r.setData({
        H: 20,
        H2: 40,
        H3: 25,
        H4: 30
      });
    }, 1e3);
    r.gethuizong();
  },
  link_detail_ps: function(a) {
    wx.navigateTo({
      url: "/hyb_jianzhi/about_us/about_us?id=" + a.currentTarget.dataset.id
    });
  },
  getUsers: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/User",
      data: {
        openid: wx.getStorageSync("openid")
      },
      success: function(a) {
        console.log(a.data.data.u_hy), t.setData({
          is_hy: a.data.data.u_hy,
          u_id: a.data.data.u_id,
          userinfo: a.data.data
        }), 0 == a.data.data.u_status && t.setData({
          close: !0
        });
      }
    });
  },
  getHuandengpian: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/Huandengpian",
      success: function(a) {
        console.log(a), t.setData({
          broadcast: a.data.data
        });
      }
    });
  },
  getPianlist: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/Pianlist",
      success: function(a) {
        t.setData({
          pianlist: a.data.data
        });
      }
    });
  },
  getPiandaohang: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/Piandaohang",
      success: function(a) {
        console.log(a), t.setData({
          daohang1: a.data.data
        }), console.log(t.data.daohang1);
      }
    });
  },
  onGotUserInfo: function(a) {
    console.log(a), "getUserInfo:ok" == a.detail.errMsg ? (wx.setStorageSync("useInfo", "true"),
      this.getGetUid(a.detail.userInfo), this.setData({
        getUseInfo: !1
      })) : this.setData({
      getUseInfo: !0
    });
  },
  getGetUid: function(t) {
    var e = this;
    wx.login({
      success: function(a) {
        a.code && app.util.request({
          url: "entry/wxapp/GetUid",
          data: {
            code: a.code
          },
          success: function(s) {
            s.data.errno || (wx.setStorageSync("openid", s.data.data.openid), console.log(s.data.data.openid),
              console.log(t), app.util.request({
                url: "entry/wxapp/TyMember",
                data: {
                  u_name: t.nickName,
                  u_thumb: t.avatarUrl,
                  u_sex: t.gender,
                  openid: s.data.data.openid
                }
              })), wx.getLocation({
              type: "wgs84",
              success: function(a) {
                var t = a.longitude,
                  e = a.latitude,
                  n = a.speed,
                  i = a.accuracy;
                app.util.request({
                  url: "entry/wxapp/Weizhi",
                  cachetime: "30",
                  data: {
                    latitude: e,
                    longitude: t,
                    openid: s.data.data.openid,
                    speed: n,
                    accuracy: i
                  }
                });
              }
            }), null != e.data.fx_popenid && "" != e.data.fx_popenid && "undefined" != e.data.fx_popenid && 1 == e.data.base.is_fx && app.util.request({
              url: "entry/wxapp/Fenxiaoaddxj",
              data: {
                fx_popenid: e.data.fx_popenid,
                openid: s.data.data.openid,
                fx_name: t.nickName,
                fx_thumb: t.avatarUrl
              }
            }), app.util.request({
              url: "entry/wxapp/User",
              data: {
                openid: s.data.data.openid
              },
              success: function(a) {
                e.setData({
                  is_hy: a.data.data.u_hy
                });
              }
            });
          }
        });
      }
    });
  },
  getJianzhi_type: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/Jianzhi_types",
      success: function(a) {
        a.data.data[0].length <= 5 ? t.setData({
          jianzhi_types: 1
        }) : t.setData({
          jianzhi_types: 2
        }), t.setData({
          jianzhi_type: a.data.data
        });
      }
    });
  },
  getDaohang: function() {
    var t = this;
    app.util.request({
      url: "entry/wxapp/Daohang",
      success: function(a) {
        console.log(a), t.setData({
          daohang: a.data.data
        });
      }
    });
  },
  getJianzhi_show: function() {
    var e = this;
    app.util.request({
      url: "entry/wxapp/Jianzhi_show",
      data: {
        city: wx.getStorageSync("city"),
        page: e.data.page,
        pagesize: e.data.pagesize,
        openid: wx.getStorageSync("openid")
      },
      success: function(a) {
        "0" != a.data.data.length && 0 < e.data.page && wx.showToast({
          title: "加载中...",
          icon: "none",
          duration: 500
        }), app.globalData.keArr = a.data.data;
        var t = e.data.page + 1;
        e.setData({
          pageWrapCount: e.data.pageWrapCount.concat([1]),
          page: t
        });
      }
    }), app.util.request({
      url: "entry/wxapp/Jianzhi_shows",
      data: {
        city: wx.getStorageSync("city"),
        page: e.data.page,
        pagesize: e.data.pagesize,
        openid: wx.getStorageSync("openid")
      },
      success: function(a) {
        console.log(a.data.data), "0" != a.data.data.length && 0 < e.data.page && wx.showToast({
          title: "加载中...",
          icon: "none",
          duration: 500
        });
        var t = e.data.page + 1;
        e.setData({
          keArrs: e.data.keArrs.concat(a.data.data),
          page: t
        });
      }
    });
  },
  sort: function(a, t) {
    for (var e = 0; e < a.length; e++)
      if (t - a[e].juli < 0) {
        var n = a.splice(e, 1);
        a.push(n[0]);
      }
  },
  timeJobDetailClick: function(a) {
    var t = a.detail.id;
    wx.navigateTo({
      url: "/hyb_jianzhi/job_detail/job_detail?j_id=" + t + "&typs=tiao"
    });
  },
  timeJobDetailClicks: function(a) {
    if ("1" == a.currentTarget.dataset.gq) wx.showToast({
      title: "此职位已过期",
      image: "/hyb_jianzhi/images/errors.png"
    });
    else {
      var t = a.currentTarget.dataset.id;
      wx.navigateTo({
        url: "/hyb_jianzhi/job_detail/job_detail?j_id=" + t + "&typs=tiao"
      });
    }
  },
  choiceClick: function(a) {
    this.getform(a.detail.formId), wx.navigateTo({
      url: "/hyb_jianzhi/position/position"
    });
  },
  searchClick: function(a) {
    this.getform(a.detail.formId), console.log(a), wx.navigateTo({
      url: "/hyb_jianzhi/search/search?city=" + this.data.a_id
    });
  },
  getform: function(a) {
      app.util.request({
      url: "entry/wxapp/Formid",
      data: {
        openid: wx.getStorageSync("openid"),
        formid: a
      },
      success: function(a) {}
    });
  },
  timeJobListClick: function(a) {
    this.getform(a.detail.formId);
    var t = a.currentTarget.dataset.title;
    wx.navigateTo({
      url: "/hyb_jianzhi/time_job_list/time_job_list?title=" + t
    });
  },
  timeJobMore: function() {
    wx.reLaunch({
      url: "/hyb_jianzhi/time_job_more/time_job_more"
    });
  },
  gethuizong: function() {
    var i = this;
    app.util.request({
      url: "entry/wxapp/Base",
      success: function(a) {
        var n = a.data.data;
        "0" == n.is_xn || "" == n.is_xn ? app.util.request({
          url: "entry/wxapp/Huizong",
          success: function(a) {
            console.log(a);
            for (var t = [{
              title: "入驻企业",
                number: a.data.data.shop
              }, {
                title: "职位",
                number: a.data.data.work
              }, {
                title: "简历",
                number: a.data.data.jianli
              }, {
                title: "访问",
                number: a.data.data.fanwen
              }], e = 0; e < t.length; e++) 5 == t[e].number.length ? 0 == t[e].number[1] ? t[e].number = t[e].number.substring(0, 1) + "万" : t[e].number = t[e].number.substring(0, 1) + "." + t[e].number.substring(1, 2) + "万" : 6 == t[e].number.length ? 0 == t[e].number[2] ? t[e].number = t[e].number.substring(0, 2) + "万" : t[e].number = t[e].number.substring(0, 2) + "." + t[e].number.substring(3, 4) + "万" : 7 == t[e].number.length && (0 == t[e].number[3] ? t[e].number = t[e].number.substring(0, 3) + "万" : t[e].number = t[e].number.substring(0, 3) + "." + t[e].number.substring(3, 4) + "万");
            i.setData({
              summary: t
            });
          }
        }) : app.util.request({
          url: "entry/wxapp/Huizong",
          success: function(a) {
            console.log(a);
            for (var t = [{
                title: "合作企业",
                number: String(parseInt(a.data.data.shop) + parseInt(n.rz_qy))
              }, {
                title: "职位数",
                number: String(parseInt(a.data.data.work) + parseInt(n.job))
              }, {
                title: "简历数",
                number: String(parseInt(a.data.data.jianli) + parseInt(n.infos))
              }, {
                title: "访问量",
                number: String(parseInt(a.data.data.fanwen) + parseInt(n.avtives))
              }], e = 0; e < t.length; e++) 5 == t[e].number.length ? 0 == t[e].number[1] ? t[e].number = t[e].number.substring(0, 1) + "万" : t[e].number = t[e].number.substring(0, 1) + "." + t[e].number.substring(1, 2) + "万" : 6 == t[e].number.length ? 0 == t[e].number[2] ? t[e].number = t[e].number.substring(0, 2) + "万" : t[e].number = t[e].number.substring(0, 2) + "." + t[e].number.substring(3, 4) + "万" : 7 == t[e].number.length && (0 == t[e].number[3] ? t[e].number = t[e].number.substring(0, 3) + "万" : t[e].number = t[e].number.substring(0, 3) + "." + t[e].number.substring(3, 4) + "万");
            i.setData({
              summary: t
            });
          }
        });
      }
    });
  },
  tiaozhuan: function(a) {
    var t = a.currentTarget.dataset.path;
    wx.navigateTo({
      url: t
    });
  },
  onReachBottom: function() {
    this.getJianzhi_show();
  },
  scroll: function(a) {
    this.setData({
      scrollTop: a.detail.scrollTop
    });
  },
  // 获得初始化数据
  getJianzhixq: function (t) {
    var g = this;
    app.util.request({
      url: "entry/wxapp/Jianzhi_infoxq",
      data: {
        openid: wx.getStorageSync("openid"),
        f_id: t
      },

      success: function (a) {
        console.log(a.data.data);
        g.setData({
          jianzhi_infoxq: a.data.data
        });
      }
    });
  },
  // 报名
  sendClick: function (a) { 
    var e = this;
    var fidd = a.detail.f_id;

    e.getform(a.detail.formId), app.util.request({
      url: "entry/wxapp/User",
      data: {
        openid: wx.getStorageSync("openid")
      },
      success: function (t) {
        // 判断会员
        console.log(t.data.data.hy);
        if (t.data.data.hy == true){
           // 是会员
          wx.getStorageSync("openid") == a.detail.f_openid ? wx.showToast({
            title: "您是发布者",
            image: "/hyb_jianzhi/images/errors.png"
          }) : "true" == a.detail.baoming ? wx.showToast({
            title: "报名已满",
            image: "/hyb_jianzhi/images/errors.png"
          }) : null == t.data.data.u_bname ? wx.showModal({
            title: "提示",
            content: "请先完善信息",
            success: function (t) {
              t.confirm && wx.navigateTo({
                url: "/hyb_jianzhi/edit/edit"
              });
            }
          }) : "待审核" == t.data.data.u_typs ? wx.showToast({
            title: "请等待审核",
            image: "/hyb_jianzhi/images/errors.png"
          }) : "不限" != a.detail.sex && t.data.data.u_sex != a.detail.sex ? wx.showToast({
            title: "不符合需求",
            image: "/hyb_jianzhi/images/errors.png"
          }) : app.util.request({
            url: "entry/wxapp/Userbaiming",
            data: {
              openid: wx.getStorageSync("openid"),
              f_id: a.detail.f_id
            },
            success: function (t) {
              // 有没有报名，没有就往下走
              if ("false" == t.data.data.baoming) {
                // 同意协议就去send写优点
                wx.showModal({
                  title: '温馨提示',
                  content: a.detail.xieyi2,
                  cancelText: '不同意',
                  confirmText: '同意',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateTo({
                        url: "/hyb_jianzhi/send/send?f_id=" + fidd
                      });
                    }
                  }
                });

              } else "true" == t.data.data.baoming && wx.showToast({
                title: "您已报名",
                image: "/hyb_jianzhi/images/errors.png"
              });
            }
          });

         
        }
        // 不是会员
        else{
          wx.showToast({
            title: "请先开通会员",
            image: "/hyb_jianzhi/images/errors.png"
          });
        }
        
      }
    });
  },

  onShareAppMessage: function() {}
});